package com.huike.controller.system;

import com.huike.dto.DepartmentDto;
import com.huike.dto.PageDepartmentDto;
import com.huike.entity.Department;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/system/department")
public class DepartmentController {

    @Autowired
    private DepartmentService departmentService;

    /**
     * 分页查询部门
     */
    @GetMapping("list")
    public Result<List<Department>> list(PageDepartmentDto dto){
        return departmentService.list(dto);
    }

    /**
     * 查询所有部门
     */
    @GetMapping("findAll")
    public Result<List<Department>> findAll(){
            return departmentService.findAllDept();
    }

    /**
     * 新增部门
     */
    @PostMapping("add")
    public Result add(@RequestBody DepartmentDto dto){
      return departmentService.add(dto);
    }

    /**
     *根据id查询回显
     */
    @GetMapping("findById/{id}")
    public Result<Department> findByid(@PathVariable Integer id){
       return departmentService.findById(id);
    }

    /**
     *修改部门
     */
    @PutMapping("update")
    public Result update(@RequestBody DepartmentDto dto){
       return departmentService.updateDepartment(dto);
    }

    /**
     *根据id删除部门
     */
    @DeleteMapping("deleteById/{id}")
    private Result deleteById(@PathVariable Integer id){
       return departmentService.deleteById(id);
    }
}
